package com.mine.androidlearn.api.Interceptor;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


/**
 * 网络实况监视
 *
 * @author mine
 * @version V1.0 2018/8/6 22:32
 */
public class LiveNetworkMonitor implements NetworkMonitor {

    private final Context applicationContext;

    public LiveNetworkMonitor(Context context) {
        applicationContext = context.getApplicationContext();
    }

    @Override
    public boolean isConnected() {
        ConnectivityManager cm = (ConnectivityManager) applicationContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    }
}
